#ifndef ICE_CAST_HTTP_H
#define ICE_CAST_HTTP_H

#include <stdio.h>
#include <string>
#include "def.h"
#include "HttpConnection.h"

class IceCastHttp
{
private:

	// find sub-string within a string
	char * findSubStrInStr(const char * data, const char * start, const char * end, int remove = 0);

	// add a slot
	void addSlotInfo(IceCastSlot *info);

	// clear all slots information
	void clearSlotsInfo();

	// HTTP connection
	HttpConnection * m_lpConnection;

	// parse login result
	const int parseLogin();

	// parse get slots info
	const int parseGetSlots();
	
	// parse get icecast server info
	const int parseGetIcecastInfo(IceCastSlot *slot);

	// current return code
	char * m_strRetCode;

	// based URL
	char * m_strBasedURL;

	// username
	char * m_strUser;

	// password
	char * m_strPass;

	// token
	char * m_strToken;

	// number of slot
	int m_nSlotCount;

	// slot info
	IceCastSlot * m_lpSlots;

	// get current return code
	const char * retCode();

	// get based URL
	const char * basedURL();

	// get token
	const char * token();

	// get user
	const char * user();

	// get password
	const char * pass();

public:

	// set based URL
	void setBasedURL(const char * url);

	// login to ice-cast server
	const int login(const char * user, const char * pass);

	// refresh slots
	const int refreshSlot();

	// get slot count
	const int slotCount();

	// get a slot by Index
	const IceCastSlot * slot(int idx);

	// get slot by ID
	const IceCastSlot * slotById(int id);

	// get current slot (current time)
	const IceCastSlot * currentSlot();

	// get current slot (current time)
	const IceCastSlot * nextSlot();

	// get available slots
	IceCastSlot * availableSlots();

	// init a stream
	const int initStream(IceCastSlot * slot);

	// free stream
	const int freeStream(IceCastSlot * slot);

	// constructor
	IceCastHttp(const char * baseURL = 0);
	~IceCastHttp();
};

#endif // ICE_CAST_HTTP_H
